import { defineStore } from 'pinia';
import { ref } from 'vue';

export interface Knowledge {
  id: string;
  name: string;
  description: string;
  type: string;
  status: 'active' | 'inactive';
}

export const useKnowledgeStore = defineStore('knowledge', () => {
  const knowledgeBases = ref<Knowledge[]>([]);

  const fetchKnowledgeBases = async () => {
    // TODO: 实现从后端获取知识库列表
    return knowledgeBases.value;
  };

  const createKnowledge = async (knowledge: Omit<Knowledge, 'id'>) => {
    // TODO: 实现创建知识库
    const newKnowledge = {
      ...knowledge,
      id: Date.now().toString()
    };
    knowledgeBases.value.push(newKnowledge);
    return newKnowledge;
  };

  const updateKnowledge = async (knowledge: Knowledge) => {
    // TODO: 实现更新知识库
    const index = knowledgeBases.value.findIndex(k => k.id === knowledge.id);
    if (index !== -1) {
      knowledgeBases.value[index] = knowledge;
    }
    return knowledge;
  };

  const deleteKnowledge = async (id: string) => {
    // TODO: 实现删除知识库
    knowledgeBases.value = knowledgeBases.value.filter(knowledge => knowledge.id !== id);
  };

  return {
    knowledgeBases,
    fetchKnowledgeBases,
    createKnowledge,
    updateKnowledge,
    deleteKnowledge
  };
}); 